package pro.cherish.knowledgewebflux.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;

import java.util.ArrayList;
import java.util.List;

import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;


/**
 * @author 创建人：lys
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2020-5-27 lys 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：SwaggerConfig
 * @Description 功能说明：Swagger配置
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2020-5-27
 */


@Configuration

@EnableSwagger2WebFlux
@Profile({"!prod"})
public class SwaggerConfig {

	private static final String TOKEN = "access_token";
	private static final String TOKEN_VALUE = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsidW5pdHktcmVzb3VyY2UiXSwidXNlclJlZ2lvbkNvZGVOb3ciOiIiLCJ1c2VyQWNjb3VudCI6ImFnZW5jeSIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJzeXN0ZW1UeXBlIjoiMyIsInVzZXJUeXBlTm93IjoiMyIsInVzZXJOYW1lIjoi5Luj55CG5py65p6E55So5oi3IiwiZXhwIjoxNTU1MTYwMTgwLCJ1c2VySWQiOiIxMTExMTMiLCJqdGkiOiI3OGE4YzZjNi0xN2JmLTQ3MDItYjU5NS0xYTk1YTY4ZWUxY2QiLCJjbGllbnRfaWQiOiJncC1nYXRld2F5LWNlbnRlciJ9.OJ_CVfo-CBMUpkxPCuSdoOmmfHtg52-jEnDFXcCIS7PTrj0LMcgmDyNHZshhUABectWmgX_xqC73-hR2SzgNSnYTXZOeswSFzoG0RR5ZC2grMFzVhwFYSTtc5TDb0qsBjGYVtTcqecUMVcqcIC24b1NvTdUM_uScgR-tLckHMaZqF9WKlDY2KeXtXzBqnXK9z-C8Z11JrzOEzmXL3hFwQTArgshDPRVpvkny1hozoxRY5CzKHl_YPkphR8MGZYe-izDbBhA8lbaqzDcNy42E_-WZYyeMMsDGYjakGb_lBjVa0dgCd0qr3csFpPJzPmxysKDBR7boC5lcBBoryHxq6Q";

	@Bean
	public Docket createRestApi() {
		ParameterBuilder tokenPar = new ParameterBuilder();
		List<Parameter> pars = new ArrayList();
		tokenPar.name(TOKEN).description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(true).defaultValue(TOKEN_VALUE).build();
		pars.add(tokenPar.build());
		return (new Docket(DocumentationType.SWAGGER_2)).select().apis(basePackage("pro.cherish.knowledgewebflux.web")).paths(PathSelectors.any()).build().globalOperationParameters(pars).apiInfo(this.apiInfo());
	}

	private ApiInfo apiInfo() {
		return (new ApiInfoBuilder()).title("消息服务swagger").description("消息服务swagger").termsOfServiceUrl("").contact(new Contact("", "", "")).version("V1").build();
	}
}
